package f.app.al;

import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListOfEntry extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list);
		ListView listView = (ListView) findViewById(R.id.ListViewId);
		Database listDatabase = new Database(this);
		List<Entry> entries;
		entries = listDatabase.getAllEntries();
		listView.setAdapter(new EntryAdapter(this, android.R.layout.simple_list_item_1, entries));
	}
	public class EntryAdapter extends ArrayAdapter<Entry> {
		private List<Entry> entries;
		
		public EntryAdapter(Context context, int textViewResourceId, List<Entry> entries) {
            super(context, textViewResourceId, entries);
      this.entries = entries;
        }
		@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
      if (v == null) {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.list_item, null);
      }
      Entry entry = entries.get(position);
      if (entries != null) {
    	  TextView name = (TextView)v.findViewById(R.id.name);
          TextView amount = (TextView)v.findViewById(R.id.amount);
          TextView date = (TextView)v.findViewById(R.id.date);

          if (amount != null) {
                    amount.setText(entry.name);
          }
          if(name != null) {
              name.setText(Integer.toString(entry.amount) + "kr");
          }
          if(date != null){
        	  date.setText(Integer.toString(entry.day) +"-" + Integer.toString(entry.month) +"-" + Integer.toString(entry.year-100));
          }
      }
      return v;
        }
    }
}

	


